<template>
	<view>
		<view class="missionHead">
			<view @click="getNaver(0)" :class="{ style: !headStyle }">已接收</view>
			<view @click="getNaver(1)" :class="{ style: headStyle }">已发布</view>
		</view>

		<view v-if="!headStyle" class="missionStatus">
			<view v-for="(item, index) in list" :key="index" :class="[{ item }, { itemStyle: showStyle == index }]" @click="changeStatus(index)">{{ item.text }}</view>
		</view>

		<view v-if="headStyle" class="missionStatus">
			<view v-for="(item, index) in issues" :key="index" :class="[{ item }, { itemStyle: showIssue == index }]" @click="getIssueNaver(index)">{{ item.text }}</view>
		</view>

		<view v-if="!headStyle" class="missionList">
			<scroll-view @scrolltolower="uploadMissioc" :style="'height:' + wh + 'px'" scroll-y="true" class="scroll">
				<view v-for="(item, index) in missionList" :key="index" class="missionItem">
					<view class="itemLeft">
						<view class="itemLeftImg">
							<image v-if="item.platform == 'douyin'" src="/static/images/douyin1.png"></image>
							<image v-else-if="item.platform == 'kuaishou'" src="/static/images/kuaishou1.png"></image>
							<image v-else src="/static/images/xhs1.png"></image>
						</view>
						<view class="itemLeft-top">
							<view>
								{{ item.task_name }}
							</view>
							<view style="color: #FE0026;">
								¥{{ item.price }}
							</view>
						</view>
					</view>
					<!-- <view class="itemCenter">
						<text v-if="item.status == 0" class="text1">待提交</text>
						<text v-if="item.status == 1" class="text2">审核中</text>
						<text v-if="item.status == 2" class="text3">已失败</text>
						<text v-if="item.status == 3" class="text4">已完成</text>
					</view> -->
					<view @click="gotoDetail(item.task_receipt_id)" class="itemRight">
						<text>查看详情</text>
						<image src="/static/images/rightclick.png"></image>
					</view>
				</view>
				<view class="over_line" v-if="isover">----- 我也是有底线的 ------</view>
				<view v-if="!missionList.length" class="notAvailable">暂无任务~</view>
			</scroll-view>
		</view>

		<view v-if="headStyle" class="myIssue">
			<scroll-view @scrolltolower="issueUploadMissioc" :style="'height:' + wh + 'px'" scroll-y="true" class="scroll">
				<view v-for="(item, index) in issueList" :key="index" class="issueItem">
					<view class="itemTop">
						<view class="itemTopLft"><image src="/static/images/douyin1.png"></image></view>
						<view class="itemTopRight">
							<view class="issueClass">{{ item.task_name }}</view>
							<view class="issueDetail">{{ item.description ? item.description : '无任务描述' }}</view>
							<view class="issueNum">
								<view>
									<text>总量:</text>
									<text>{{ item.count.total }}</text>
								</view>
								<view>
									<text class="toReceive">待领取:</text>
									<text>{{ item.count.no_receive }}</text>
								</view>
							</view>
							<view class="issueNum">
								<view>
									<text class="alreadyReceive">已领取:</text>
									<text>{{ item.count.receive }}</text>
								</view>
								<view>
									<text class="audit">审核中:</text>
									<text>{{ item.count.pass }}</text>
								</view>
							</view>
							<view class="issueNum">
								<view>
									<text class="error">已失败:</text>
									<text>{{ item.count.fail }}</text>
								</view>
								<view>
									<text class="success">已完成:</text>
									<text>{{ item.count.success }}</text>
								</view>
							</view>
							<view class="itemBtm">
								<view class="endTime" v-if="item.end_time">截止时间:{{ item.end_time }}</view>
								<view v-else>截止时间:无</view>
								<view class="total">
									<text>任务总额:</text>
									<text style="color: #FF0001;">￥</text>
									<text class="totalNum">{{ item.amount }}</text>
									<view @click="gotoAudit(item.task_id)" class="examine">
										<text>查看详情</text>
										<image src="/static/images/rightclick.png"></image>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="over_line" v-if="issueIsover">----- 我也是有底线的 ------</view>
				<view v-if="!issueList.length" class="notAvailable">暂无任务~</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [
				{
					text: '待提交'
				},
				{
					text: '待审核'
				},
				{
					text: '已失败'
				},
				{
					text: '已完成'
				}
			],
			issues: [
				{
					text: '进行中'
				},
				{
					text: '已完成'
				}
			],
			showStyle: 0,
			showIssue: 0,
			headStyle: 0,
			wh: '', // 当前屏幕可用的高度
			missionList: [],
			issueList: [],
			pagenum: 1, // 页码值
			pagesize: 15, // 每页显示多少条数据
			receiveTotal: '',
			isover: false, // 判断是否到底部，给用户提示
			isloading: false, // 判断数据是否在加载中
			issuePagenum: 1, // 页码值
			issuePagesize: 15, // 每页显示多少条数据
			issueTotal: '',
			issueIsover: false, // 判断是否到底部，给用户提示
			issueIsloading: false // 判断数据是否在加载中
		};
	},
	onLoad(option) {
		let that = this;
		uni.getSystemInfo({
			success: function(res) {
				that.wh = res.windowHeight - 175;
			}
		});
		if(option.issue == 1) {
			that.headStyle = 1
		}else {
			that.showStyle = option.id;
		}
		that.getIssueList(that.showIssue)
	},
	onShow() {
		this.missionList = [];
		this.isloading = false;
		this.isover = false;
		this.pagenum = 1;
		this.receiveTotal = '';
		this.getMissionList();
	},
	methods: {
		// 切换已接收已发布导航栏
		getNaver(index) {
			if(this.headStyle == index) return
			this.headStyle = index;
			// if (!this.headStyle) {
			// 	this.getMissionList(this.showStyle)
			// } else {
			// 	this.getIssueList(this.showIssue)
			// }
		},

		// 切换已发布状态  获取已发任务数据列表
		getIssueNaver(index) {
			if(this.showIssue == index) return
			this.showIssue = index;
			this.issueList = [];
			this.issueIsover = false;
			this.issueIsloading = false;
			this.issuePagenum = 1;
			this.issueTotal = '';
			this.getIssueList(index);
		},
		// 切换已接收状态  获取已接收任务数据列表
		changeStatus(index) {
			if(this.showStyle == index) return
			this.showStyle = index;
			this.missionList = [];
			this.isloading = false;
			this.isover = false;
			this.pagenum = 1;
			this.receiveTotal = '';
			this.getMissionList();
		},

		// 获取已接任务数据列表
		getMissionList() {
			// 正在加载下页数据
			this.isloading = true;
			this.$api.getUserTaskList({
					type:'user',
					page: this.pagenum,
					limit: this.pagesize,
					status: this.showStyle
				},res => {
					this.receiveTotal = res.data.count;
					this.missionList = [...this.missionList, ...res.data.list];
					// 没有在加载下页数据
					this.isloading = false;
				});
		},

		// 获取已发任务数据列表
		getIssueList(index) {
			// 正在加载下页数据
			this.issueIsloading = true;
			this.$api.getPostList({
					page: this.issuePagenum,
					limit: this.issuePagesize,
					status: index
				},res => {
					this.issueTotal = res.data.count;
					this.issueList = [...this.issueList, ...res.data.list];
					// 没有在加载下页数据
					this.issueIsloading = false;
				});
		},

		// 已接收滚动到底部加载任务数据
		uploadMissioc() {
			if (!this.missionList.length) {
				return;
			}
			// 判断当前是否正在请求数据中
			if (this.isloading) {
				return;
			}
			if (this.pagesize * this.pagenum >= this.receiveTotal) {
				this.isover = true;
				return;
			}
			this.pagenum++;
			this.getMissionList();
		},

		// 已发布滚动到底部加载任务数据
		issueUploadMissioc() {
			if (!this.issueList.length) {
				return;
			}
			// 判断当前是否正在请求数据中
			if (this.issueIsloading) {
				return;
			}
			if (this.issuePagesize * this.issuePagenum >= this.issueTotal) {
				this.issueIsover = true;
				return;
			}
			this.issuePagenum++;
			this.getIssueList(this.showIssue);
		},

		// 跳转到已接任务详情页
		gotoDetail(id) {
			uni.navigateTo({
				url: `/pages/users/mission_detail/mission_detail?id=${id}`
			});
		},
		// 跳转到已发布任务列表
		gotoAudit(id) {
			uni.navigateTo({
				url: `/pages/users/user-audit/user-audit?id=${id}`
			});
		}
	}
};
</script>

<style lang="less">
page {
	background-color: #ffffff;
}
.missionHead {
	display: flex;
	justify-content: space-around;
	align-items: center;
	height: 250rpx;
	background: url(../../../static/images/background8.png) no-repeat;
	background-size: 100%;
	margin: 20rpx 0;
	view {
		width: 144rpx;
		height: 44rpx;
		color: #ffffff;
		text-align: center;
		line-height: 44rpx;
	}
	.style {
		background: #ffffff;
		border-radius: 22rpx;
		color: #f19725;
	}
}
.missionStatus {
	display: flex;
	justify-content: space-around;
	background-color: #ffffff;
	.item {
		position: relative;
		font-size: 30rpx;
		font-weight: bold;
		color: #b8b8b8;
		z-index: 1;
	}
	.itemStyle {
		color: #000000;
	}
	.itemStyle::before {
		content: '';
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		background-color: #ffe287;
		width: 100%;
		height: 13rpx;
		border-radius: 5rpx;
		z-index: -1;
	}
}

.missionList {
	padding: 20rpx 20rpx 0;
	background-color: #ffffff;
	.scroll {
		overflow: hidden;
		.notAvailable {
			width: 100%;
			height: 150rpx;
			text-align: center;
			line-height: 200rpx;
			font-size: 24rpx;
			color: #666;
		}
		.over_line {
			text-align: center;
			font-size: 26rpx;
			color: #999;
			padding: 20rpx 0;
		}
		.missionItem {
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1rpx solid #eeeeee;
			padding: 20rpx 0;
			.itemLeft {
				display: flex;
				align-items: center;
				flex: 1;
				overflow: hidden;
				.itemLeftImg {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					margin-right: 25rpx;
					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}
				.itemLeft-top {
					flex: 1;
					overflow: hidden;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #343434;
					view:first-child {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}
				.itemLeft-bom {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #9a9a9a;
					line-height: 36rpx;
					margin-left: 10rpx;
				}
			}
			// .itemCenter {
			// 	margin-right: 120rpx;
			// 	font-size: 24rpx;
			// 	.text1 {
			// 		color: #5256ff;
			// 	}
			// 	.text2 {
			// 		color: #fcae14;
			// 	}
			// 	.text3 {
			// 		color: #ee4c48;
			// 	}
			// 	.text4 {
			// 		color: #84cc2c;
			// 	}
			// }
			.itemRight {
				font-size: 24rpx;
				font-weight: 500;
				color: #666666;
				text {
					vertical-align: middle;
					margin-right: 15rpx;
				}
				image {
					width: 12rpx;
					height: 22rpx;
					vertical-align: middle;
					margin-top: 5rpx;
				}
			}
		}
	}
}

.myIssue {
	padding: 20rpx 20rpx 0;
	background-color: #ffffff;
	.scroll {
		overflow: hidden;
		.notAvailable {
			width: 100%;
			height: 150rpx;
			text-align: center;
			line-height: 200rpx;
			font-size: 24rpx;
			color: #666;
		}
		.over_line {
			text-align: center;
			font-size: 26rpx;
			color: #999;
			padding: 20rpx 0;
		}
		.issueItem {
			margin-bottom: 20rpx;
			background-color: #f5f5f5;
			width: 712rpx;
			height: 480rpx;
			border-radius: 10rpx;
			padding: 30rpx;
			.itemTop {
				display: flex;
				.itemTopLft {
					width: 80rpx;
					height: 80rpx;
					margin-right: 30rpx;
					margin-top: 10rpx;
					image {
						width: 100%;
						height: 100%;
					}
				}
				.itemTopRight {
					flex: 1;
					line-height: 60rpx;
					font-size: 30rpx;
					.issueClass {
						color: #2a2929;
					}
					.issueDetail {
						width: 542rpx;
						font-size: 28rpx;
						color: #9a9a9a;
						white-space: nowrap;
						text-overflow: ellipsis;
						overflow: hidden;
					}
					.issueNum {
						display: flex;
						view {
							flex: 1;
							text:first-child {
								margin-right: 10rpx;
							}
						}
						.toReceive {
							color: #84cc2c;
						}
						.alreadyReceive {
							color: #fcae14;
						}
						.audit {
							color: #5256ff;
						}
						.error {
							color: #ee4c48;
						}
						.success {
							color: #84cc2c;
						}
					}
					.itemBtm {
						// display: flex;
						// justify-content: space-between;
						// align-items: center;
						font-size: 30rpx;
						color: #504e52;
						.endTime {
							flex: 1;
							margin-top: 8rpx;
							white-space: nowrap;
						}
						.total {
							white-space: nowrap;
							.totalNum {
								font-size: 42rpx;
								color: #ff0001;
							}
							.examine {
								float: right;
								font-weight: 500;
								color: #666666;
								text {
									vertical-align: middle;
									margin-right: 15rpx;
								}
								image {
									width: 12rpx;
									height: 22rpx;
									vertical-align: middle;
									margin-top: 5rpx;
								}
							}
						}
					}
				}
			}

			.itemBtm {
				// display: flex;
				// justify-content: space-between;
				// align-items: center;
				font-size: 30rpx;
				color: #504e52;
				.endTime {
					flex: 1;
					margin-top: 8rpx;
					white-space: nowrap;
				}
				.total {
					white-space: nowrap;
					.totalNum {
						font-size: 42rpx;
						color: #ff0001;
					}
				}
			}
		}
		.issueItem:last-child {
			margin-bottom: 0;
		}
	}
}
</style>
